#pragma once
#include "BaseAcc.h"
#include "AABB.h"
#include "Cell.h"

namespace mray{

struct Ray;

//arrange index by order xyz
struct Grid : public BaseAcc{
	Grid();
	virtual ~Grid();

	void Build(const std::vector<Collible*>& collibles) override;
	bool Hit(Ray& ray, Result* pResult = nullptr)const override;

private:

	uint GetIndex(uint x, uint y, uint z)const{
		return (z*m_nGrids[1]+y)*m_nGrids[0]+x;
	}

	void Print()const;

	AABB	m_box;
	float	m_cellLen;
	uint	m_nGrids[3];
	Cell*	m_pCells;
};

}